package pl.ciaastek.ubuntucontrol;

import com.jcraft.jsch.Session;

import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;

public class SettingsActivity extends PreferenceActivity implements
		OnSharedPreferenceChangeListener {

	public static Session session = null;

	@SuppressWarnings("deprecation")
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		addPreferencesFromResource(R.xml.settings);
		SharedPreferences sp = getPreferenceScreen().getSharedPreferences();
		sp.registerOnSharedPreferenceChangeListener(this);
		SharedPreferences sharedPreferences = PreferenceManager
				.getDefaultSharedPreferences(this);
		String server = sharedPreferences.getString("prefServer",
				getString(R.string.pref_server_address_summary));
		EditTextPreference prefServer = (EditTextPreference) findPreference("prefServer");
		prefServer.setSummary(server);

		String username = sharedPreferences.getString("prefUsername",
				getString(R.string.pref_server_username_summary));
		EditTextPreference prefUsername = (EditTextPreference) findPreference("prefUsername");
		prefUsername.setSummary(username);

	}

	@Override
	@SuppressWarnings("deprecation")
	public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
			String key) {
		Preference pref = findPreference("prefServer");
		if (pref instanceof EditTextPreference) {
			EditTextPreference etp = (EditTextPreference) pref;
			pref.setSummary(etp.getText());
		}
		Preference pref1 = findPreference("prefUsername");
		if (pref1 instanceof EditTextPreference) {
			EditTextPreference etp = (EditTextPreference) pref1;
			pref1.setSummary(etp.getText());
		}
	}
}
